/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CFrmLogin.java
 *
 * Created on 08/12/2010, 18:00:35
 */

package rpt.lib.ctace;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author Roberto
 */
public class CFrmLogin extends javax.swing.JFrame {

    private JFrame fJanelaPrincipal = null;

    /** Creates new form CFrmLogin */
    public CFrmLogin(final JFrame aJanelaPrincipal) {
        initComponents();
        fJanelaPrincipal = aJanelaPrincipal;
        //this.setAlwaysOnTop(true);
        //Dimension d = new Dimension(400,200);
        //setPreferredSize(d);
        //setMinimumSize(d);
        this.setBounds(100, 100, 400, 200);
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        init();
    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CFrmLogin(null).setVisible(true);
            }
        });
    }

    public void init() {
        Container content_pane = getContentPane();

        // Grab the image.
        Image img = Toolkit.getDefaultToolkit().getImage("c:\\SIN\\logo-ipem-mg.jpg");

        // Create an instanceof CImagePanel
        CImagePanel drawing_panel = new CImagePanel(img);

        // Add the CImagePanel to the content pane.
        //content_pane.add(drawing_panel,BorderLayout.CENTER);
        swPnlImagemLogo.add(drawing_panel,BorderLayout.CENTER);
    } // init

    class CImagePanel extends JPanel {

        Image img;

        CImagePanel(Image img) {
            this.img = img;
        }

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);

            // Use the image width & height to find the starting point
            int imgX = (getSize().width - img.getWidth(this)) / 2 ;
            int imgY = (getSize().height - img.getHeight(this)) / 2 ;

            //Draw image centered in the middle of the panel
            // g.drawImage(img, imgX, imgY, this);
            g.drawImage(img, 0, 0, getSize().width, getSize().height, this);
        } // paintComponent
    } // CImagePanel

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        swPnlLoginSenha = new javax.swing.JPanel();
        swLblLogin = new javax.swing.JLabel();
        swTxfLogin = new javax.swing.JTextField();
        swLblSenha = new javax.swing.JLabel();
        jPasswordField1 = new javax.swing.JPasswordField();
        swPnlImagemLogo = new javax.swing.JPanel();
        swPnBotoes = new javax.swing.JPanel();
        swBtnOk = new javax.swing.JButton();
        swBtnSair = new javax.swing.JButton();

        jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jPanel2.setMinimumSize(new java.awt.Dimension(300, 50));
        jPanel2.setPreferredSize(new java.awt.Dimension(300, 50));
        jPanel2.setLayout(new java.awt.BorderLayout());

        swPnlLoginSenha.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        swPnlLoginSenha.setFont(new java.awt.Font("Brush Script MT", 0, 36));
        swPnlLoginSenha.setMaximumSize(new java.awt.Dimension(150, 50));
        swPnlLoginSenha.setMinimumSize(new java.awt.Dimension(150, 50));
        swPnlLoginSenha.setPreferredSize(new java.awt.Dimension(185, 50));

        swLblLogin.setFont(new java.awt.Font("Arial", 0, 12));
        swLblLogin.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        swLblLogin.setText("Login");
        swLblLogin.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        swLblLogin.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        swLblLogin.setInheritsPopupMenu(false);

        swTxfLogin.setFont(new java.awt.Font("Arial", 0, 12));
        swTxfLogin.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        swLblSenha.setFont(new java.awt.Font("Arial", 0, 12));
        swLblSenha.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        swLblSenha.setText("Senha");
        swLblSenha.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        swLblSenha.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        swLblSenha.setInheritsPopupMenu(false);

        jPasswordField1.setFont(new java.awt.Font("Arial", 0, 12));
        jPasswordField1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        javax.swing.GroupLayout swPnlLoginSenhaLayout = new javax.swing.GroupLayout(swPnlLoginSenha);
        swPnlLoginSenha.setLayout(swPnlLoginSenhaLayout);
        swPnlLoginSenhaLayout.setHorizontalGroup(
            swPnlLoginSenhaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(swPnlLoginSenhaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(swLblLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(swTxfLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(swLblSenha, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPasswordField1, javax.swing.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE)
                .addContainerGap())
        );
        swPnlLoginSenhaLayout.setVerticalGroup(
            swPnlLoginSenhaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(swPnlLoginSenhaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(swPnlLoginSenhaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(swLblLogin)
                    .addComponent(swTxfLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(swLblSenha))
                .addContainerGap(16, Short.MAX_VALUE))
        );

        jPanel2.add(swPnlLoginSenha, java.awt.BorderLayout.NORTH);

        swPnlImagemLogo.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        swPnlImagemLogo.setLayout(new java.awt.BorderLayout());
        jPanel2.add(swPnlImagemLogo, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);

        swPnBotoes.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        swPnBotoes.setPreferredSize(new java.awt.Dimension(300, 50));

        swBtnOk.setText("OK");
        swBtnOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                swBtnOkActionPerformed(evt);
            }
        });

        swBtnSair.setText("SAIR");
        swBtnSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                swBtnSairActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout swPnBotoesLayout = new javax.swing.GroupLayout(swPnBotoes);
        swPnBotoes.setLayout(swPnBotoesLayout);
        swPnBotoesLayout.setHorizontalGroup(
            swPnBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(swPnBotoesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(swBtnOk)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(swBtnSair)
                .addContainerGap(357, Short.MAX_VALUE))
        );
        swPnBotoesLayout.setVerticalGroup(
            swPnBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(swPnBotoesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(swPnBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(swBtnOk)
                    .addComponent(swBtnSair))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        getContentPane().add(swPnBotoes, java.awt.BorderLayout.SOUTH);
    }// </editor-fold>//GEN-END:initComponents

    private void swBtnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_swBtnOkActionPerformed
        fJanelaPrincipal.setVisible(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        this.dispose();
    }//GEN-LAST:event_swBtnOkActionPerformed

    private void swBtnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_swBtnSairActionPerformed
        this.dispose();
    }//GEN-LAST:event_swBtnSairActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JButton swBtnOk;
    private javax.swing.JButton swBtnSair;
    private javax.swing.JLabel swLblLogin;
    private javax.swing.JLabel swLblSenha;
    private javax.swing.JPanel swPnBotoes;
    private javax.swing.JPanel swPnlImagemLogo;
    private javax.swing.JPanel swPnlLoginSenha;
    private javax.swing.JTextField swTxfLogin;
    // End of variables declaration//GEN-END:variables

}
